package com.gugee.tiktok.common.model.mysql;

import com.gugee.tiktok.common.model.spider.blogger.User;
import com.xiguaji.boot.data.rdb.aggregate.Aggregate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table
public class Blogger extends Aggregate {
    /**
     * o_avatar_300x300
     */
    private String oAvatar300;

    /**
     * o_uid
     */
    private long oUid;

    /**
     * o_avatar_medium
     */
    private String oAvatarMedium;

    /**
     * 被关注数
     */
    private int oFollowerCount;

    private long oAvgViews;

    private long oAvgLikes;

    private long oAvgReviews;

    private long oAvgShare;

    /**
     * 区域
     */
    private String oDistrict;

    /**
     * 签名
     */
    private String oSignature;

    /**
     * 平台关注数
     */
    private int oMplatformFollowersCount;

    /**
     * o_cover_url
     */
    private String oCoverUrl;

    /**
     * o_is_star
     */
    private boolean oIsStar;

    /**
     * 主动关注数
     */
    private int oFollowingCount;

    /**
     * 总点赞数
     */
    private long oTotalFavorited;

    /**
     * o_dongtai_count
     */
    private int oDongtaiCount;

    /**
     * o_avatar_168x168
     */
    private String oAvatar168;

    /**
     * 性别
     */
    private int oGender;

    /**
     * o_share_info
     */
    private String oShareInfo;

    /**
     * o_avatar_larger
     */
    private String oAvatarLarger;

    /**
     * o_birthday
     */
    private String oBirthday;

    /**
     * o_country
     */
    private String oCountry;

    /**
     * o_city
     */
    private String oCity;

    /**
     * o_is_activity_user
     */
    private boolean oIsActivityUser;

    /**
     * o_avatar_thumb
     */
    private String oAvatarThumb;

    /**
     * o_province
     */
    private String oProvince;

    /**
     * o_aweme_count
     */
    private int oAwemeCount;

    /**
     * o_location
     */
    private String oLocation;

    /**
     * o_sec_uid
     */
    private String oSecUid;

    /**
     * o_nickname
     */
    private String oNickname;

    /**
     * o_room_id
     */
    private long oRoomId;

    /**
     * o_region
     */
    private String oRegion;

    /**
     * o_video_icon
     */
    private String oVideoIcon;

    private String oUniqueId;

    private int oConstellation;
    /**
     *企业蓝V认证
     */
    private String oEnterpriseVerifyReason;
    /**
     *是否开通购物车
     */
    private boolean oWithFusionShopEntry;

    /**
     *个人主页website
     */
    private String bioUrl;
    /**
     *企业蓝V认证
     */
    private String enterpriseVerifyReason;
    /**
     *是否开通购物车
     */
    private Boolean withFusionShopEntry;
    /**
     *个人蓝V认证
     */
    private String customVerify;

    /**
     *youtube账号id
     */
    private String youtubeChannelId;
    /**
     *twitter账号id
     */
    private String twitterId;
    /**
     * instagram账号id
     */
    private String insId;
    /**
     * Email
     */

    private String bioEmail;

    /**
     * ai分析年龄(0:未分析;1:未知;其余的该是几岁就几岁
     */
    private int aiAge = 0;

    /**
     * ai分析性别(0:未分析;1:未知;2:女;3:男)
     */
    private int aiGender = 0;

    /**
     * 分析性别的来源依据(0:头像分析;1:标签分析;2:人工审核)
     */
    private Integer genderSource;

    /**
     * 博主状态
     */
    private int tiktokerStatus = 0;

    @Mapper(componentModel = "spring")
    public interface BloggerMapper {
        @Mapping(target = "oAvatar300", expression = "java(getAvatar_300x300(dto))")
        @Mapping(target = "oUid", source = "uid")
        @Mapping(target = "oAvatarMedium", expression = "java(getAvatar_medium(dto))")
        @Mapping(target = "oFollowerCount", source = "follower_count")
        @Mapping(target = "oDistrict", source = "district")
        @Mapping(target = "oSignature", source = "signature")
        @Mapping(target = "oMplatformFollowersCount", source = "mplatform_followers_count")
        @Mapping(target = "oCoverUrl", expression = "java(getCover_url(dto))")
        @Mapping(target = "oIsStar", source = "is_star")
        @Mapping(target = "oFollowingCount", source = "following_count")
        @Mapping(target = "oTotalFavorited", source = "total_favorited")
        @Mapping(target = "oDongtaiCount", source = "dongtai_count")
        @Mapping(target = "oAvatar168", expression = "java(getAvatar_168x168(dto))")
        @Mapping(target = "oGender", source = "gender")
        @Mapping(target = "oShareInfo", expression = "java(getShare_info(dto))")
        @Mapping(target = "oAvatarLarger", expression = "java(getAvatar_larger(dto))")
        @Mapping(target = "oBirthday", source = "birthday")
        @Mapping(target = "oCountry", source = "country")
        @Mapping(target = "oCity", source = "city")
        @Mapping(target = "oIsActivityUser", source = "is_activity_user")
        @Mapping(target = "oAvatarThumb", expression = "java(getAvatar_thumb(dto))")
        @Mapping(target = "oProvince", source = "province")
        @Mapping(target = "oAwemeCount", source = "aweme_count")
        @Mapping(target = "oLocation", source = "location")
        @Mapping(target = "oSecUid", source = "sec_uid")
        @Mapping(target = "oNickname", source = "nickname")
        @Mapping(target = "oRoomId", source = "room_id")
        @Mapping(target = "oRegion", source = "region")
        @Mapping(target = "oVideoIcon", expression = "java(getVideo_icon(dto))")
        @Mapping(target = "oUniqueId", source = "unique_id")
        @Mapping(target = "oConstellation", source = "constellation")
//        @Mapping(target = "oEnterpriseVerifyReason", source = "enterprise_verify_reason")
//        @Mapping(target = "oWithFusionShopEntry", source = "oWithFusionShopEntry")
        @Mapping(target = "bioUrl", source = "bioUrl")
        @Mapping(target = "enterpriseVerifyReason", source = "enterpriseVerifyReason")
        @Mapping(target = "customVerify", source = "customVerify")
        @Mapping(target = "withFusionShopEntry", source = "withFusionShopEntry")
        @Mapping(target = "youtubeChannelId", source = "youtubeChannelId")
        @Mapping(target = "twitterId", source = "twitterId")
        @Mapping(target = "insId", source = "insId")
        @Mapping(target = "bioEmail", source = "bioEmail")

        Blogger mapper(User dto);

        List<Blogger> mapper(List<User> dtos);

        default String getVideo_icon(User dto) {
            if (dto.getVideo_icon() == null || CollectionUtils.isEmpty(dto.getVideo_icon().getUrl_list())) {
                return "";
            }
            return dto.getVideo_icon().getUrl_list().get(0);
        }

        default String getCover_url(User dto) {
            if (CollectionUtils.isEmpty(dto.getCover_url())) return "";
            return dto.getCover_url().get(0).getUrl_list().get(0);
        }

        default String getShare_info(User dto) {
            return dto.getShare_info() == null ? "" : dto.getShare_info().getShare_url();
        }

        default String getAvatar_thumb(User dto) {
            if (CollectionUtils.isEmpty(dto.getAvatar_thumb().getUrl_list())) return "";
            return dto.getAvatar_thumb().getUrl_list().get(0);
        }

        default String getAvatar_larger(User dto){
            if (CollectionUtils.isEmpty(dto.getAvatar_larger().getUrl_list())) return "";
            return dto.getAvatar_larger().getUrl_list().get(0);
        }

        default String getAvatar_168x168(User dto){
            if (CollectionUtils.isEmpty(dto.getAvatar_168x168().getUrl_list())) return "";
            return dto.getAvatar_168x168().getUrl_list().get(0);
        }

        default String getAvatar_medium(User dto){
            if (CollectionUtils.isEmpty(dto.getAvatar_medium().getUrl_list())) return "";
            return dto.getAvatar_medium().getUrl_list().get(0);
        }

        default String getAvatar_300x300(User dto){
            if (CollectionUtils.isEmpty(dto.getAvatar_300x300().getUrl_list())) return "";
            return dto.getAvatar_300x300().getUrl_list().get(0);
        }
    }
}
